package com.didi.gulimall.product.service.impl;

import com.didi.gulimall.product.dao.BrandDao;
import com.didi.gulimall.product.entity.BrandEntity;
import com.didi.gulimall.product.service.BrandService;
import com.didi.gulimall.product.service.CategoryBrandRelationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.didi.gulimall.common.utils.PageUtils;
import com.didi.gulimall.common.utils.Query;

import javax.annotation.Resource;


/**
 * @author 10626
 */
@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {
    @Resource
    private CategoryBrandRelationService categoryBrandRelationService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                new QueryWrapper<BrandEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void updateBrand(BrandEntity brand) {
      this.baseMapper.updateById(brand);
      if (StringUtils.isNotBlank(brand.getName())){
          categoryBrandRelationService.updateBrand(brand.getBrandId(),brand.getName());
      }
    }

    @Override
    public List<BrandEntity> infoList(List<Long> brands) {
        return baseMapper.selectList(new QueryWrapper<BrandEntity>().in("brand_id",brands));
    }

}